package com.acwing.partition35;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/18 9:28
 */
public class AC3438数制转换 {

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        int n1 = Integer.parseInt(ss[0]), n2 = Integer.parseInt(ss[2]);
        String src = ss[1];
        int ori = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = src.length() - 1, j = 0; i >= 0; i--, j++) ori += Math.pow(n1, j) * get(src.charAt(i));
        while (ori != 0) {
            int t = ori % n2;
            sb.insert(0, get(t));
            ori /= n2;
        }
        writer.write(sb + "\n");
        writer.flush();
    }

    private static int get(char ch) {
        if (ch >= 'A' && ch <= 'Z') return 10 + ch - 'A';
        if (ch >= 'a' && ch <= 'z') return 10 + ch - 'a';
        return ch - '0';
    }

    private static char get(int n) {
        if (n >= 0 && n <= 9) return (char) (n + '0');
        return (char) ('A' + n - 10);
    }
}
